package com.mysterymall.Common.Config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        List<String>  filtrationList = new ArrayList<>();


        // 登录 注册
        filtrationList.add("/user/login");
        filtrationList.add("/user/logout");
        filtrationList.add("/user/registration");


        // 试玩
        filtrationList.add("/blindBoxGroup/getTestGoods");
        filtrationList.add("/blindBoxGroup/getShowBlindBoxGroupMonocle");


        // 盲盒组
        filtrationList.add("/blindBoxGroup/getShowBoxGroup");
        filtrationList.add("/blindBoxGroup/getBoxGroupGoodsNotice");
        filtrationList.add("/marketing/getCustomerServiceUser");

        // 验证码
        filtrationList.add("/sms/turingTest");
        filtrationList.add("/sms/turingTestCode");
        filtrationList.add("/sms/sendVerify");

        // 商品列表
        filtrationList.add("/goods/getShopList");

        // 图片映射
        filtrationList.add("/images/**");
        filtrationList.add("/dingdang/**");
        filtrationList.add("/videos/**");

        // 支付回调
        filtrationList.add("/payment/placeAnOrderCallback");



        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/**")
                .excludePathPatterns(filtrationList);
    }
}
